<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/5/19
  Time: 9:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <META charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="/js/common.js"></script>
<%--    <script src="/js/user.js" charset="UTF-8"></script>--%>
</head>
<script>
    $(function () {
        chaxun();
    });

    function chaxun() {
        $.ajax({
            url: '/userFindAll',
            data: '',
            type: 'get',
            dataType: 'json',
            success: function (data) {
                setData(data[0].object);
            }
        })
    }

    function setData(data) {
        // data = JSON.stringify(data);
        let html = '';
        for (let i = 0; i < data.length; i++) {
            html += '<tr>\n' +
                '        <td>' + data[i].id + '</td>\n' +
                '        <td width="200px">' + data[i].username + '</td>\n' +
                '        <td>' + data[i].password + '</td>\n' +
                '        <td> <a href="javascript:update(' + data[i].id + ')">编辑</a> ' +
                ' <a href="javascript:del(' + data[i].id + ')">删除</a></td>\n' +
                '    </tr>';
        }
        $("#companyTbody").html(html);
    }

    function update(id) {
        localStorage.setItem("userId", id);
        $('#homeright').load('/back/userUpdate.jsp');
    }

    function del(id) {
        let userId = localStorage.setItem("userId", id);
        myAjax('/userDel', {id, userId}, 'post');
        $('#homeright').load('/back/usermanage.jsp');
    }
</script>
<body>
<table class="table table-hover">
    <thead>
    <tr>
        <td>id</td>
        <td width="200px">用户名称</td>
        <td>用户密码</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody id="companyTbody">
    </tbody>
</table>
</body>
</html>
